package com.yu1996.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.yu1996.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 *
 * @author Administrator
 */
public interface ProblemDao extends JpaRepository<Problem, String>, JpaSpecificationExecutor<Problem> {


    /**
     * @param labelId  标签id
     * @param pageable 分页对象
     * @return org.springframework.data.domain.Page<com.yu1996.qa.pojo.Problem>
     * @description 根据标签 查询最新的问题
     * @date 2019/10/11 21:27
     */
    @Query(value = "SELECT * from tb_problem , tb_pl where id = problemid AND labelid = ? ", nativeQuery = true)
    Page<Problem> newList(String labelId, Pageable pageable);

    /**
     * @param labelId  标签id
     * @param pageable 分页对象
     * @return org.springframework.data.domain.Page<com.yu1996.qa.pojo.Problem>
     * @description 根据标签 查询最热的问题
     * @date 2019/10/11 21:27
     */
    @Query(value = "SELECT * from tb_problem , tb_pl where id = problemid AND labelid = ? ORDER BY reply DESC", nativeQuery = true)
    Page<Problem> hotList(String labelId, Pageable pageable);

    /**
     * @param labelId  标签id
     * @param pageable 分页对象
     * @return org.springframework.data.domain.Page<com.yu1996.qa.pojo.Problem>
     * @description 根据标签 查询等待回答的问题
     * @date 2019/10/11 21:27
     */
    @Query(value = "SELECT * from tb_problem , tb_pl where id = problemid AND labelid = ? AND reply = \"0\" ORDER BY replytime ", nativeQuery = true)
    Page<Problem> waitList(String labelId, Pageable pageable);
}
